using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Controladoras;
using EntidadesTO;
using System.Collections.Generic;

public partial class FrmBuscarPredioPopup : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.txtPpCodPredio.Text = "";
            this.txtPpDptoPredio.Text = "";
            this.txtPpIntPredio.Text = "";
            this.txtPpNomVia.Text = "";
            this.txtPpNroPredio.Text = "";
            //PredioMantenedor.ObtenerInstancia().CargarListaConFiltro(-1, "", -1, "", "", -1);

            //Int32.Parse(this.txtPpCodPredio.Text), this.txtPpNomVia.Text, Int32.Parse(this.txtPpNroPredio.Text),
            //                                                     this.txtPpIntPredio.Text, this.txtPpDptoPredio.Text, Int32.Parse(this.cmbPpDistrito.SelectedValue)
            this.dgvPredio.DataSource = null; //PredioMantenedor.ObtenerInstancia().ListaPredio;
            this.dgvPredio.DataBind();

            this.CascadingDropDown1.SelectedValue = null;
            this.CascadingDropDown2.ContextKey = null;
            this.CascadingDropDown3.ContextKey = null;
            this.CascadingDropDown4.ContextKey = null;
        }
        
        
    }

    public void LimpiarFiltros()
    {
        this.txtPpCodPredio.Text = "";
        this.txtPpDptoPredio.Text = "";
        this.txtPpIntPredio.Text = "";
        this.txtPpNomVia.Text = "";
        this.txtPpNroPredio.Text = "";

        this.dgvPredio.DataSource = null;
        this.dgvPredio.DataBind();

        this.CascadingDropDown1.SelectedValue = null;
        this.CascadingDropDown2.ContextKey = null;
        this.CascadingDropDown3.ContextKey = null;
        this.CascadingDropDown4.ContextKey = null;
    }

    protected void btnBuscarPredio_Click(object sender, EventArgs e)
    {
        int lcodPredio;
        int lnroPredio;
        int lsecDistrito;

        try
        {
            if (this.txtPpCodPredio.Text == "")
                lcodPredio = -1;
            else
                lcodPredio = Int32.Parse(this.txtPpCodPredio.Text);

            if (this.txtPpNroPredio.Text == "")
                lnroPredio = -1;
            else
                lnroPredio = Int32.Parse(this.txtPpNroPredio.Text);

            if (this.cmbPpDistrito.SelectedValue == "")
                lsecDistrito = -1;
            else
                lsecDistrito = Int32.Parse(this.cmbPpDistrito.SelectedValue);

            PredioMantenedor.ObtenerInstancia().CargarListaConFiltro(lcodPredio, this.txtPpNomVia.Text, lnroPredio, this.txtPpIntPredio.Text, this.txtPpDptoPredio.Text, lsecDistrito);
            this.dgvPredio.DataSource = PredioMantenedor.ObtenerInstancia().ListaPredio;
            this.dgvPredio.DataBind();

        }
        catch (Exception ex)
        {
            ex.ToString();
        }
    }

    public List<PredioTO> obtenerPredioSeleccionado()
    {
        PredioTO predioSeleccionado;
        List<PredioTO> listaPredioSeleccionado = new List<PredioTO>();

        for (int i = 0; i < this.dgvPredio.Rows.Count; i++)
        {
            if ((((CheckBox)this.dgvPredio.Rows[i].FindControl("chkSeleccionado")).Checked))
            {
                int codigo = (int)dgvPredio.DataKeys[i].Value;
                PredioMantenedor.ObtenerInstancia().BuscarPorLlave(codigo);
                predioSeleccionado = PredioMantenedor.ObtenerInstancia().ListaPredio[0];

                listaPredioSeleccionado.Add(predioSeleccionado);
            }
        }
        return listaPredioSeleccionado;
    }
    protected void btnLimpiarPredio_Click(object sender, EventArgs e)
    {
        LimpiarFiltros();
    }
}
